global X "md_taxmult pref_left altitude_min altitude altitude_max area lake expo lfindex castle wealthtax1940 population foreigners young old primary secondary tertiary agglo center dist_center tourist medinc gini high_educ mid_educ low_educ unemployment"
global bX "bmd_taxmult, bpref_left, baltitude_min, baltitude, baltitude_max, barea, blake, bexpo, blfindex, bcastle, bwealthtax1940, bpopulation, bforeigners, byoung, bold, bprimary, bsecondary, btertiary, bagglo, bcenter, bdist_center, btourist, bmedinc, bgini, bhigh_educ, bmid_educ, blow_educ, bunemployment"
global vX "vmd_taxmult, vpref_left, valtitude_min, valtitude, valtitude_max, varea, vlake, vexpo, vlfindex, vcastle, vwealthtax1940, vpopulation, vforeigners, vyoung, vold, vprimary, vsecondary, vtertiary, vagglo, vcenter, vdist_center, vtourist, vmedinc, vgini, vhigh_educ, vmid_educ, vlow_educ, vunemployment"

* =================
* = SUMMARY STAT  =
* =================

foreach x in $X {
ivreg2 `x'  if dist >=-40 & dist <=40, cluster(gdenr year)
est store `x'
local name="`x'"
mat b`x'=_b[_cons]
mat v`x'= _se[_cons]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
sum md_taxmult if french == 1   & (dist >=-40 & dist <= 40)  
local nb_french = round(r(N)/$y_count)
sum md_taxmult if french == 0   & (dist >=-40 & dist <= 40) 
local nb_german = round(r(N)/$y_count)
sum md_taxmult if (dist >= -20 & dist <= 20)
local nb_border = round(r(N)/$y_count)
sum md_taxmult if (dist >= -40 & dist < -20) | (dist > 20 & dist <= 40)
local nb_nonborder = round(r(N)/$y_count)
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T3, replace  nose noaster bdec(2) onecol nor2 ctitle("Mean")  bracket addstat("No. French-speaking municipalities", `nb_french', "No. German-speaking municipalities", `nb_german', "No. border municipalities", `nb_border', "No. non-border municipalities", `nb_nonborder')

foreach x in $X {
ivreg2 `x' french if dist >=-20 & dist <=20, cluster(gdenr year)
est store `x'
local name="`x'"
mat b`x'=_b[french]
mat v`x'= _se[french]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
sum md_taxmult if french == 1   & (dist >=-20 & dist <=20)
local nb_french = round(r(N)/$y_count)
sum md_taxmult if french == 0   & (dist >=-20 & dist <=20)
local nb_german = round(r(N)/$y_count)
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T3,  nose onecol nor2 bdec(2) ctitle("French-German difference" "0-20 km")  bracket addstat("No. French-speaking municipalities", `nb_french', "No. German-speaking municipalities", `nb_german')

foreach x in $X {
ivreg2 `x' french if (dist >=-40 & dist <-20) | (dist >20 & dist <=40) , cluster(gdenr year)
est store `x'
local name="`x'"
mat b`x'=_b[french]
mat v`x'= _se[french]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
sum md_taxmult if french == 1   & ((dist >=-40 & dist <-20) | (dist >20 & dist <=40)) 
local nb_french = round(r(N)/$y_count)
sum md_taxmult if french == 0   & ((dist >=-40 & dist <-20) | (dist >20 & dist <=40)) 
local nb_german = round(r(N)/$y_count)
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T3,  nose onecol nor2 bdec(2) ctitle("French-German difference" "21-40 km")  bracket addstat("No. French-speaking municipalities", `nb_french', "No. German-speaking municipalities", `nb_german')


foreach x in $X {
ivreg2 `x' border if (dist >=0 & dist <=40), cluster(gdenr year)
est store `x'
local name="`x'"
mat b`x'=_b[border]
mat v`x'= _se[border]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
sum md_taxmult if (dist >= 0 & dist <=20)
local nb_border = round(r(N)/$y_count)
sum md_taxmult if (dist > 20 & dist <=40)
local nb_nonborder = round(r(N)/$y_count)
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T3,  nose bdec(2) onecol nor2 ctitle("Within difference" "French")  bracket addstat("No. border municipalities", `nb_border', "No. non-border municipalities", `nb_nonborder')


foreach x in $X {
ivreg2 `x' border if (dist >=-40 & dist <0), cluster(gdenr year)
est store `x'
local name="`x'"
mat b`x'=_b[border]
mat v`x'= _se[border]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
sum md_taxmult if (dist >= -20 & dist <0)
local nb_border = round(r(N)/$y_count)
sum md_taxmult if (dist >= -40 & dist < -20)
local nb_nonborder = round(r(N)/$y_count)
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T3,  nose bdec(2) onecol nor2 ctitle("Within difference" "German")  bracket addstat("No. border municipalities", `nb_border', "No. non-border municipalities", `nb_nonborder')


foreach x in $X {
ivreg2 `x' french border int_bfr if (dist >=-40 & dist <= 40), cluster(gdenr year)
est store `x'
local name="`x'"
mat b`x'=_b[int_bfr]
mat v`x'= _se[int_bfr]^2
matrix coleq b`x' = `name'
matrix coleq v`x' = `name'
}
sum md_taxmult if french == 1   & (dist >=-40 & dist <= 40)  
local nb_french = round(r(N)/$y_count)
sum md_taxmult if french == 0   & (dist >=-40 & dist <= 40) 
local nb_german = round(r(N)/$y_count)
sum md_taxmult if (dist >= -20 & dist <= 20)
local nb_border = round(r(N)/$y_count)
sum md_taxmult if (dist >= -40 & dist < -20) | (dist > 20 & dist <= 40)
local nb_nonborder = round(r(N)/$y_count)
mat b= $bX
mat v= $vX
mat V=diag(v)
eret post b V
outreg2 using tables/T3,  nose onecol nor2 bdec(2) ctitle("DiD" "0-40 km")  bracket addstat("No. French-speaking municipalities", `nb_french', "No. German-speaking municipalities", `nb_german', "No. border municipalities", `nb_border', "No. non-border municipalities", `nb_nonborder')
